#include <gtest/gtest.h>
#include "src/symbols/radicals/radical_semantic.h"

class RadicalSemanticTest : public ::testing::Test {
protected:
    void SetUp() override {
        // 初始化字根语义库
        RadicalSemantic::initialize();
    }

    void TearDown() override {
        // 清理测试环境
    }
};

TEST_F(RadicalSemanticTest, GetSemanticVector) {
    // 测试获取语义向量
    SemanticVector vector = RadicalSemantic::getSemanticVector("人");
    
    // 向量不应该为空
    EXPECT_GT(vector.size(), 0);
}

TEST_F(RadicalSemanticTest, VectorOperations) {
    // 测试向量运算
    SemanticVector v1({1.0, 2.0, 3.0});
    SemanticVector v2({2.0, 3.0, 4.0});
    
    // 向量加法
    SemanticVector sum = v1 + v2;
    EXPECT_EQ(sum[0], 3.0);
    EXPECT_EQ(sum[1], 5.0);
    EXPECT_EQ(sum[2], 7.0);
    
    // 向量数乘
    SemanticVector scaled = v1 * 2.0;
    EXPECT_EQ(scaled[0], 2.0);
    EXPECT_EQ(scaled[1], 4.0);
    EXPECT_EQ(scaled[2], 6.0);
}

TEST_F(RadicalSemanticTest, CosineSimilarity) {
    // 测试余弦相似度
    SemanticVector v1({1.0, 0.0, 0.0});
    SemanticVector v2({0.0, 1.0, 0.0});
    SemanticVector v3({1.0, 0.0, 0.0});
    
    // 正交向量的余弦相似度应该为0
    double similarity1 = v1.cosineSimilarity(v2);
    EXPECT_NEAR(similarity1, 0.0, 1e-6);
    
    // 相同向量的余弦相似度应该为1
    double similarity2 = v1.cosineSimilarity(v3);
    EXPECT_NEAR(similarity2, 1.0, 1e-6);
}